﻿<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <router-view v-if="isRouterAlive"></router-view>
    <div class="content-header">
        <h1>会员管理
            <small>会员档案</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>会员管理</el-breadcrumb-item>
            <el-breadcrumb-item>体检上传</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号" v-model="queryData.queryString_fileNumber" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-input placeholder="姓名" v-model="queryData.queryString_name" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-input placeholder="手机号" v-model="queryData.queryString_phone" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPageByConditions()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleAdd()">新建</el-button>
                <el-button @click="del()" type="danger">删除</el-button>
            </div>
            <el-table
                    ref="multipleTable"
                    tooltip-effect="dark"
                    style="width: 100%"
                    @selection-change="handleSelectionChange"
                    :data="dataList">
                <el-table-column
                        type="selection"
                        width="55">
                </el-table-column>
                <el-table-column prop="health_time" label="体检时间" align="center"></el-table-column>
                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号" align="center"></el-table-column>

                <el-table-column prop="setmeal" label="检测套餐" align="center"></el-table-column>
                <el-table-column prop="status" label="报告状态" align="center">
                    <template slot-scope="scope">
                        <span>{{scope.row.status == '1' ? '报告已上传' : '报告未上传'}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="upload(scope.row)">上传报告</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog :title="title" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" label-position="right"  :rules="rules"
                             label-width="100px">
                        <template>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="手机号" prop="phoneNumber" :error="errorMsg">
                                        <el-input v-model="formData.phoneNumber"
                                                  v-on:blur="findMessage(formData.phoneNumber)"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="姓名" prop="name">
                                        <el-input v-model="formData.name" :readonly="true"/>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="档案号" prop="fileNumber">
                                        <el-input v-model="formData.fileNumber" :readonly="true"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="套餐" prop="setmeal">
                                        <el-input v-model="formData.setmeal" :readonly="true"/>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="体检时间" prop="health_time">
                                        <el-date-picker
                                                v-model="formData.health_time"
                                                type="date"
                                                placeholder="选择日期"
                                                format="yyyy 年 MM 月 dd 日"
                                                value-format="yyyy-MM-dd">
                                        </el-date-picker>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </template>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleSubmit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!-- 导入弹出框 -->
            <div class="add-form">
                <el-dialog title="上传报告" :visible.sync="dialogFormVisibleUpload">
                    <el-form ref="dataAddForm" :model="formData" label-position="right"  :rules="rules"
                             label-width="100px">
                        <template>
                            <el-row>
                                <el-col :span="12">
                                <el-button style="margin-bottom: 20px;margin-right: 20px" type="primary"
                                           @click="downloadTemplate()">模板下载</el-button>
                                </el-col>
                                <el-col :span="12">
                                <el-upload action="/upload/upload.do"
                                           name="excelFile"
                                           :show-file-list="false"
                                           :on-success="handleSuccess"
                                           :before-upload="beforeUpload">
                                    <el-button type="primary">上传文件</el-button>
                                </el-col>
                                </el-upload>
                            </el-row>
                        </template>
                    </el-form>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    var vue = new Vue({
        /*局部刷新*/
        inject: ['reload'],
        provide() {
            return {
                reload: this.reload
            }
        },
        el: '#app',
        data: {
            isRouterAlive: true,
            options: [],
            title: '新增',//标签栏名称
            errorMsg:'',//动态错误提示
            // pageFlag: 0,//判断是否是第一次带查询条件查询
            activeName: 'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100
            },
            queryData: {//查询条件
                queryString_fileNumber: null,
                queryString_name: null,
                queryString_phone: null
            },
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisibleUpload:false,//控制上传窗口显示/隐藏
            rules: {//校验规则
                phoneNumber: [{required: true, message: '手机号为必填项', trigger: 'blur'}],
                health_time: [{type: 'string', required: true, message: '体检时间为必填项', trigger: 'blur'}],
            },
            multipleSelection: [],
            ids: []
        },
        created() {
            this.findPage();
        },
        methods: {
            /*局部刷新*/
            reload() {
                this.isRouterAlive = false;
                this.$nextTick(function () {
                    this.isRouterAlive = true
                })
            },
            //清除验证样式
            clearValidate() {
                this.$refs['dataAddForm'].clearValidate();
            },
            handleAdd() {
                this.resetForm();
                this.dialogFormVisible = true;
                this.clearValidate();
            },
            handleSubmit() {
                this.$refs['dataAddForm'].validate((valid) => {
                    alert(valid);
                    this.dialogFormVisible = false;
                    if (valid) {
                        // alert(this.formData.health_time);
                        axios.post("/upload/add.do", this.formData).then((res) => {
                            if (res.data.flag) {
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                })
                            } else {
                                this.$message.error(res.data.message);
                            }
                        }).finally(() => {
                            //重置验证  没起作用
                            this.$refs['dataAddForm'].clearValidate();
                            this.findPage();
                        })
                    } else {
                        return false;
                    }
                })
            },
            findPageByConditions() {
                /**
                 * 这个是解决分页查询 带条件 查询结果的当前页不是第一页
                 * 解决办法 只有当点击查询按钮的时候 将当前页置为1
                 */
                this.pagination.currentPage = 1;
                this.findPage();
            },
            //分页查询
            findPage() {
                let param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryData: this.queryData
                };

                axios.post("/upload/findByPage.do", param).then((res) => {
                    this.dataList = res.data.rows;
                    this.pagination.total = res.data.total
                })

            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            del() {
                if (this.multipleSelection == undefined || this.multipleSelection.length <= 0) {
                    this.$message.error("请选择删除对象!");
                } else {
                    this.$confirm('确认删除？').then(_ => {
                        if (this.multipleSelection != null) {
                            this.multipleSelection.forEach(row => {
                                this.ids.push(row.id);
                            })
                        }
                        this.handleDelete();
                    })
                }
            },
            // 删除
            handleDelete(row) {
                if (row != null) {
                    this.ids.push(row.id);
                    this.$confirm('确认删除？')
                        .then(_ => {
                            axios.get("/upload/delete.do?id=" + this.ids).then((res) => {
                                if (res.data.flag) {
                                    this.$message({
                                        message: res.data.message,
                                        type: 'success'
                                    });
                                    this.ids = [];
                                } else {
                                    this.$message.error(res.data.message);
                                    this.ids = [];
                                }
                            }).catch(_ => {
                            }).finally(() => {
                                this.findPage();
                            });
                        })
                } else {
                    axios.get("/upload/delete.do?id=" + this.ids).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                            this.ids = [];
                        } else {
                            this.$message.error(res.data.message);
                            this.ids = [];
                        }
                    }).catch(_ => {
                    }).finally(() => {
                        this.findPage();
                    });
                }
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            //根据手机号查询信息 参数传递的是用户输入的手机号
            findMessage(phoneNumber) {
                this.errorMsg='';
                this.formData.name = '';
                this.formData.fileNumber = '';
                this.formData.setmeal = '';
                //如果手机号为空则不触发后台校验
                if (phoneNumber != null) {
                    //
                    // axios.post("/upload/selectPhone.do?phoneNumber=" + phoneNumber).then((res)=>{
                    //     if(!res.data.flag){
                    //         this.errorMsg=res.data.message;
                    //         return false;
                    //     }
                    // });
                    axios.post("/upload/findByPhone.do?phoneNumber=" + phoneNumber).then((res) => {
                        if(!res.data.flag){
                            this.errorMsg=res.data.message;
                            return false;
                        }
                        this.formData.name = res.data.data.name;
                        this.formData.fileNumber = res.data.data.fileNumber;
                        this.formData.setmeal = res.data.data.setmeal;
                        /*局部刷新*/
                        this.reload();
                    })
                }
            },
            upload(row){
                this.dialogFormVisibleUpload=true;
            },
            downloadTemplate(){
                window.location.href="../../template/physical_examination_template.xlsx";
            },
            //上传成功提示
            handleSuccess(response, file) {
                if(response.flag){
                    this.$message({
                        message: response.message,
                        type: 'success'
                    });
                    this.dialogFormVisibleUpload=false;
                }else{
                    this.$message.error(response.message);
                }
                // console.log(response, file, fileList);
            },
        }
    })
</script>
</html>
